package com.firexxx.study.performancetest.task;

import com.firexxx.study.performancetest.task.rest.RestArg;
import com.firexxx.study.web.RestTemplateHandler;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.List;

/**
 * 添加通用的时间消耗类操作来模拟业务，用于测试锁、并发性能
 *
 * @author fireXXX
 * @date 2020/11/19 0:14
 **/
public abstract class IRestPressureTestTask extends ITask {

    @Getter
    private RestTemplateHandler restTemplateHandler;
    @Getter
    private List<Pair<Long, Long>> results = new ArrayList<>();
    @Getter
    private String url = "";

    public void init(Object args) {
        RestArg restArg = (RestArg) args;

        restTemplateHandler = restArg.getRestTemplateHandler();
        url = restArg.getUrl();

        results.clear();
    }

    public void saveResult(Object obj) {
        results.add(Pair.of(System.currentTimeMillis(), (Long) obj));
    }

}